package com.db.stockexchange.common.messages;

public enum MessageType {
	LOGON("A"), 
	LOGOUT("5"), 
	EXEC_REPORT("8"), 
	REJECT("3"), 
	NEW_ORDER("D"), 
	CANCEL_ORDER("F");
	
	String type;
	
	MessageType(String type) {
		this.type = type;
	}
	
	public static MessageType fromString(String type) {
		switch (type) {
		case "A": return LOGON;
		case "5": return LOGOUT;
		case "8": return EXEC_REPORT;
		case "3": return REJECT;
		case "D": return NEW_ORDER;
		case "F": return CANCEL_ORDER;
		default:
			throw new IllegalArgumentException("Illegal message type");
		}
	}
	
	public String asString() {
		return type;
	}
}
